summaryrefslogtreecommitdiff
path: root/src/pages/micro/[...page].astro
blob: d11d9cefd79ebbeabe5b6d411275ef484ea0d14a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
import { type CollectionEntry, getCollection } from "astro:content";
import type { GetStaticPaths, Page } from "astro";
import { Icon } from "astro-icon/components";
import Note from "@/components/note/Note.astro";
import Pagination from "@/components/Paginator.astro";
import PageLayout from "@/layouts/Base.astro";

export const getStaticPaths = (async ({ paginate }) => {
	const MAX_MICRO_PER_PAGE = 10;

	// Get only Pleroma posts tagged with "micro"
	const allMicro = await getCollection("micro", ({ data }) => data.tags?.includes("micro")).catch(
		() => [],
	); // Fallback to empty array if micro collection fails

	// Sort all micro posts
	const allMicroPosts = allMicro.sort(
		(a, b) => b.data.publishDate.getTime() - a.data.publishDate.getTime(),
	);

	return paginate(allMicroPosts, { pageSize: MAX_MICRO_PER_PAGE });
}) satisfies GetStaticPaths;

interface Props {
	page: Page<CollectionEntry<"micro">>;
	uniqueTags: string[];
}

const { page } = Astro.props;

const meta = {
	description: "Read my collection of micro posts",
	title: "Micro",
};

const paginationProps = {
	...(page.url.prev && {
		prevUrl: {
			text: "← Previous Page",
			url: page.url.prev,
		},
	}),
	...(page.url.next && {
		nextUrl: {
			text: "Next Page →",
			url: page.url.next,
		},
	}),
};
---

<PageLayout meta={meta}>
	<section>
		<h1 class="title mb-6 flex items-center gap-3">
			Micro
			<a class="text-accent" href="/tags/" title="Browse all tags">
				<span class="sr-only">Browse tags</span>
				<Icon aria-hidden="true" class="h-6 w-6" focusable="false" name="mdi:tag-multiple" />
			</a>
			<a class="text-accent" href="/tags/micro/rss.xml" target="_blank">
				<span class="sr-only">RSS feed</span>
				<Icon aria-hidden="true" class="h-6 w-6" focusable="false" name="mdi:rss" />
			</a>
		</h1>
		<ul class="mt-6 space-y-8 text-start">
			{
				page.data.map((note) => (
					<li class="">
						<Note note={note} as="h2" isPreview />
					</li>
				))
			}
		</ul>
		<Pagination {...paginationProps} />
	</section>
</PageLayout>